//
//  YWEquipmentDetailViewController.m
//  maintain
//
//  Created by Kyo on 16/4/6.
//  Copyright © 2016年 ewin. All rights reserved.
//
#import "MJExtension.h"
#import "MJRefresh.h"
#import "NSDate+Additions.h"
#import "UIColor+CustomColors.h"
#import "UIImageView+WebCache.h"
#import "UIView+Extension.h"
#import "WMHttpTool.h"
#import "YWCommonTool.h"
#import "YWConst.h"
#import "YWEquipmentType.h"
#import "YWEquipment.h"
#import "YWEquipmentDetailCell.h"
#import "YWEquipmentDetailViewController.h"
#import "YWEquipmentFieldRecord.h"
#import "YWEquipmentManager.h"
#import "YWEquipmentMoreDetailTableViewController.h"
//#import "YWImageView.h"
#import "YWPhotoView.h"
#import "YWInspecEquipmentRecordDetailTableViewController.h"
#import "YWInspectionEquipmentRecord.h"
#import "YWKeepWatchMissionManager.h"
#import "YWLastMaintenanceTime.h"
#import "YWMacro.h"
#import "YWMaintenanceRecordDetailTableViewController.h"
#import "YWMissionManager.h"
#import "YWTroubleRecordsDetailTableViewController.h"
#import "YWBuildingManager.h"
#import "YWBuilding.h"
#import "YWInspectionMissionManager.h"
#import "YWDetectAndUpkeepManager.h"
#import "YWTroubleMissionManager.h"

#define KEquipmentImageSize 63

@interface YWEquipmentDetailViewController () <UITableViewDataSource, UITableViewDelegate> {
//    NSTimeInterval troubleListRecordMinCompleteTime;
//    NSTimeInterval inspectionListRecordMinCompleteTime;
//    NSTimeInterval detectListRecordMinCompleteTime;
//    NSTimeInterval upkeepListRecordMinCompleteTime;
}
@property (nonatomic, strong) UIView* headView;
@property (nonatomic, strong) UITableView* tableView;
@property (nonatomic, strong) NSMutableArray* recordArray;
//设备名称
@property (nonatomic, strong) UILabel* equipmentNameLabel;
//设备图片
@property (nonatomic, strong) YWPhotoView* equipmentImageView;


@property (nonatomic, strong)UILabel *ownCodeLabel;
//型号
@property (nonatomic, strong)UILabel *modelLabel;
//厂商
@property (nonatomic, strong)UILabel *manufacturersLabel;
/**生产日期*/
@property (nonatomic, strong)UILabel *productDateLabel;
//安装日期
@property (nonatomic, strong)UILabel *installDateLabel;
//上次检测时间
@property (nonatomic, strong)UILabel *lastMaintenceTimeLabel;
//使用年限
@property (nonatomic, strong)UILabel *userYearLabel;

@property (nonatomic, assign) NSInteger page;
@property (nonatomic, strong) NSMutableArray* equipmentDataSource;
@property (nonatomic, strong) NSMutableArray* titleDataSource;
@end

@implementation YWEquipmentDetailViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"维保记录详情";
    self.view.backgroundColor = [UIColor customBackgroudColor];
    self.automaticallyAdjustsScrollViewInsets = NO;

    self.page = 1;
    self.tableView.backgroundColor = [UIColor customBackgroudColor];

    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshTop)];
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(refreshFootor)];
    self.tableView.mj_footer.automaticallyHidden = YES;
    // 马上进入刷新状态
    [self.tableView.mj_header beginRefreshing];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSMutableArray*)recordArray
{
    if (!_recordArray) {
        NSMutableArray* recordArray = [NSMutableArray array];
        [recordArray addObjectsFromArray:[[YWMissionManager shareManager] maintenanceRecordsWithEquipmentId:self.equipment.equipmentId andPage:self.page]];
        //获取记录图片
        __block NSDate* lastDate = nil;
        [recordArray enumerateObjectsUsingBlock:^(id _Nonnull record, NSUInteger idx, BOOL* _Nonnull stop) {
            if ([record isKindOfClass:[YWInspectionEquipmentRecord class]]) {
                YWInspectionEquipmentRecord* equipmentRecord = (YWInspectionEquipmentRecord*)record;
                equipmentRecord.pictures = [[YWKeepWatchMissionManager shareManager] recordPictureWithRecordId:equipmentRecord.equipmentRecordId recordType:YWPictureRecordTypeInspectionMission];
                NSDate* completeDate = [NSDate dateWithTimeIntervalSince1970:equipmentRecord.executeTime / 1000];
                if (completeDate.year == lastDate.year && completeDate.month == lastDate.month && completeDate.day == lastDate.day) {
                    equipmentRecord.dayMonthString = nil;
                }
                else {
                    if (completeDate.isToday) {
                        equipmentRecord.dayMonthString = @"今天";
                    }
                }
                lastDate = completeDate;
            }
            else {
                YWEquipmentMaintenanceRecord* maintanceRecord = (YWEquipmentMaintenanceRecord*)record;
                if (maintanceRecord.maintenanceTypeId == YWMaintenanceTypeTrouble) {
                    maintanceRecord.recordPictures = [[YWMissionManager shareManager] picturesWithTroubleRecordId:maintanceRecord.recordId pictureTroubleType:YWPictureTroubleTypeRecord];
                }
                else {
                    maintanceRecord.recordPictures = [[YWMissionManager shareManager] picturesWithRecordId:maintanceRecord.recordId maintenanceType:maintanceRecord.maintenanceTypeId];
                }
                NSDate* completeDate = [NSDate dateWithTimeIntervalSince1970:maintanceRecord.completeTime / 1000];
                if (completeDate.year == lastDate.year && completeDate.month == lastDate.month && completeDate.day == lastDate.day) {
                    maintanceRecord.dayMonthString = nil;
                }
                else {
                    if (completeDate.isToday) {
                        maintanceRecord.dayMonthString = @"今天";
                    }
                }
                lastDate = completeDate;
            }

        }];
        _recordArray = recordArray;
//        [self getMaintainTypeMissionMinCreateTime];
    }
    return _recordArray;
}

- (NSMutableArray*)titleDataSource{
    if (!_titleDataSource) {
        _titleDataSource = [NSMutableArray array];
        [_titleDataSource addObjectsFromArray:@[@[@""],@[self.equipmentNameLabel.text?:@"",@"用户自编码",@"出厂编号",@"设备型号",@"设备厂商",@"使用年限",@"初始参数",@"使用方法和范围"],@[@"生产日期",@"采购日期",@"安装日期"]]];
    }
    return _titleDataSource;
}


- (NSMutableArray*)equipmentDataSource
{
    if (!_equipmentDataSource) {
        _equipmentDataSource = [NSMutableArray array];
        
        NSMutableArray *buliding = [NSMutableArray array];
//        楼盘名
        [buliding addObject:[[YWBuildingManager shareManager]buildingWithId:self.equipment.buildingId].buildingName?:@"未填写"];
//        几期几层几号
        [buliding addObject:[[YWBuildingManager shareManager] equipmentLocationNobuilding:self.equipment]?:@"未填写"];
        [_equipmentDataSource addObject:buliding];
        
        NSMutableArray *equipment = [NSMutableArray array];
//        设备名称 设备名在titleDataSource中
        [equipment addObject:@""];
//        自编码
        [equipment addObject:self.equipment.ownCode.length?self.equipment.ownCode:@"未填写"];
//        出厂编号
        [equipment addObject:self.equipment.factoryCode.length?self.equipment.factoryCode: @"未填写"];
//        设备型号
        [equipment addObject:self.equipment.model.length?self.equipment.model:@"未填写"];
//        设备厂商
        [equipment addObject:self.equipment.factoryName.length?self.equipment.factoryName:@"未填写"];
//        使用年限
        [equipment addObject:self.equipment.durableYears>0?[NSString stringWithFormat:@"%ld年",(long)self.equipment.durableYears]:@"未填写"];
        //初始参数
        [equipment addObject:@""];
        //使用方法和范围
        [equipment addObject:@""];
        [_equipmentDataSource addObject:equipment];
        
        NSMutableArray *date = [NSMutableArray array];
//        生产日期
        [date addObject:self.equipment.produceDate>0?[YWCommonTool showChineseFormatterDate:self.equipment.produceDate / 1000]:@"未填写"];
        //        采购日期
        [date addObject:self.equipment.buyDate>0?[YWCommonTool showChineseFormatterDate:self.equipment.buyDate/1000]:@"未填写"];
//        安装日期
        [date addObject:self.equipment.installDate>0?[YWCommonTool showChineseFormatterDate:self.equipment.installDate / 1000]:@"未填写"];

        [_equipmentDataSource addObject:date];
    }
    return _equipmentDataSource;
}
- (void)refreshTop
{
    self.page = 1;
    [self.tableView.mj_footer resetNoMoreData];
    [self requestData:YWTableViewFreshTypeDown];
}

- (void)refreshFootor
{
    [self requestData:YWTableViewFreshTypeUp];
}

- (void)requestData:(YWTableViewFreshType)refreshType
{
    dispatch_group_t group = dispatch_group_create();
    if (refreshType == YWTableViewFreshTypeUp) {
        self.page++;
    }
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        //巡查
        dispatch_group_enter(group);
        [[YWInspectionMissionManager shareManager] requestInspectionEquipmentRecordWithEquipmentIds:self.equipment.equipmentId page:_page pageSize:10 completeBlock:^(NSInteger count) {
            dispatch_group_leave(group);
        }];

        //检测
        dispatch_group_enter(group);
        [YWDetectAndUpkeepManager requestEquipmentDetectAndUpkeepRecordWithMaintenanceTypeId:YWMaintenanceTypeDetection equipmentIds:self.equipment.equipmentId page:_page pageSize:10 completeBlock:^(NSInteger count) {
            dispatch_group_leave(group);
        }];
        //保养
        dispatch_group_enter(group);
        [YWDetectAndUpkeepManager requestEquipmentDetectAndUpkeepRecordWithMaintenanceTypeId:YWMaintenanceTypeUpkeep equipmentIds:self.equipment.equipmentId page:_page pageSize:10 completeBlock:^(NSInteger count) {
            dispatch_group_leave(group);
        }];
        //维修
        dispatch_group_enter(group);
        [[YWTroubleMissionManager shareManager] requestTroubleRecordWithEquipmentIds:self.equipment.equipmentId page:_page pageSize:10 completeBlock:^(NSInteger count) {
            dispatch_group_leave(group);
        }];
        
        YWWeakSelf(weakSelf);
        dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
        dispatch_async(dispatch_get_main_queue(), ^{
            if (refreshType == YWTableViewFreshTypeDown) {
                [weakSelf.tableView.mj_header endRefreshing];
            }
            else {
                [weakSelf.tableView.mj_footer endRefreshing];
            }
            weakSelf.recordArray = nil;
            [weakSelf.tableView reloadData];
        });
    });
}

#pragma mark - Common methods

//- (void)getMaintainTypeMissionMinCreateTime
//{
//    troubleListRecordMinCompleteTime = 0;
//    inspectionListRecordMinCompleteTime = 0;
//    detectListRecordMinCompleteTime = 0;
//    upkeepListRecordMinCompleteTime = 0;
//    for (id object in _recordArray) {
//        if ([object isKindOfClass:[YWInspectionEquipmentRecord class]]) {
//            YWInspectionEquipmentRecord* equipmentRecord = (YWInspectionEquipmentRecord*)object;
//            inspectionListRecordMinCompleteTime = inspectionListRecordMinCompleteTime ? MIN(inspectionListRecordMinCompleteTime, equipmentRecord.executeTime) : equipmentRecord.executeTime;
//        }
//        else {
//            YWEquipmentMaintenanceRecord* record = (YWEquipmentMaintenanceRecord*)object;
//            if (record.maintenanceTypeId == YWMaintenanceTypeTrouble) {
//                troubleListRecordMinCompleteTime = troubleListRecordMinCompleteTime ? MIN(troubleListRecordMinCompleteTime, record.completeTime) : record.completeTime;
//            }
//            else if (record.maintenanceTypeId == YWMaintenanceTypeDetection) {
//                detectListRecordMinCompleteTime = detectListRecordMinCompleteTime ? MIN(detectListRecordMinCompleteTime, record.completeTime) : record.completeTime;
//            }
//            else if (record.maintenanceTypeId == YWMaintenanceTypeUpkeep) {
//                upkeepListRecordMinCompleteTime = upkeepListRecordMinCompleteTime ? MIN(upkeepListRecordMinCompleteTime, record.completeTime) : record.completeTime;
//            }
//        }
//    }
//}

#pragma mark - UITableViewDataSource
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
    return 54;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
{
    return self.recordArray.count;
}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    YWEquipmentDetailCell* cell = [YWEquipmentDetailCell cellWithTableView:tableView];
    id record = self.recordArray[indexPath.section];
    if ([record isKindOfClass:[YWInspectionEquipmentRecord class]]) {
        YWInspectionEquipmentRecord* equipmentRecord = (YWInspectionEquipmentRecord*)record;
        cell.inspectionEquipmentRecord = equipmentRecord;
    }
    else {
        YWEquipmentMaintenanceRecord* maintanceRecord = (YWEquipmentMaintenanceRecord*)record;
        cell.maintenanceRecord = maintanceRecord;
    }

    return cell;
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    id object = self.recordArray[indexPath.section];
    if ([object isKindOfClass:[YWEquipmentTroubleRecord class]]) {
        YWTroubleRecordsDetailTableViewController* troubleDetailVC = [[YWTroubleRecordsDetailTableViewController alloc] init];
        //troubleDetailVC.locationId = self.equipment.locationId;
        troubleDetailVC.troubleRecord = (YWEquipmentTroubleRecord*)object;
        [self.navigationController pushViewController:troubleDetailVC animated:YES];
    }
    else if ([object isKindOfClass:[YWEquipmentMaintenanceRecord class]]) {
        YWMaintenanceRecordDetailTableViewController* maintenanceVC = [[YWMaintenanceRecordDetailTableViewController alloc] init];
        maintenanceVC.maintenanceRecord = (YWEquipmentMaintenanceRecord*)object;
        [self.navigationController pushViewController:maintenanceVC animated:YES];
    }
    else if ([object isKindOfClass:[YWInspectionEquipmentRecord class]]) {
        YWInspecEquipmentRecordDetailTableViewController* equipmentDetailRecord = [[YWInspecEquipmentRecordDetailTableViewController alloc] init];
        equipmentDetailRecord.inspectionEquipmentRecord = (YWInspectionEquipmentRecord*)object;
        [self.navigationController pushViewController:equipmentDetailRecord animated:YES];
    }
}

- (UITableView*)tableView
{
    if (!_tableView) {
        UITableView* tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStyleGrouped];
        tableView.backgroundColor = [UIColor customBackgroudColor];
        tableView.sectionHeaderHeight = 19;
        tableView.sectionFooterHeight = 1.0;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.tableHeaderView = self.headView;
        [self.view addSubview:tableView];
        _tableView = tableView;
    }
    return _tableView;
}
- (UIView*)headView
{
    if (!_headView) {
        UIView* headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kGapH*2 + kLabelH*5 + KEquipmentImageSize * 2 / 3)];
        headView.backgroundColor = [UIColor whiteColor];
        //        CGFloat labelW = SCREEN_WIDTH-kMarginW*2;
        CGFloat leftLabelW = (SCREEN_WIDTH-kMarginW*3)/2+20;
        CGFloat rightLabelW = (SCREEN_WIDTH-kMarginW*3)/2-20;
        CGFloat ownCodeWidth = SCREEN_WIDTH-kMarginW*2;
        [self.ownCodeLabel setFrame:CGRectMake(kMarginW, kGapH, ownCodeWidth, kLabelH)];
        
        [self.manufacturersLabel setFrame:CGRectMake(kMarginW, CGRectGetMaxY(self.ownCodeLabel.frame), ownCodeWidth, kLabelH)];
        [self.productDateLabel setFrame:CGRectMake(kMarginW, CGRectGetMaxY(self.manufacturersLabel.frame), leftLabelW, kLabelH)];
        [self.userYearLabel setFrame:CGRectMake(CGRectGetMaxX(self.productDateLabel.frame)+kMarginW, CGRectGetMaxY(self.manufacturersLabel.frame), rightLabelW, kLabelH)];
        
        [self.installDateLabel setFrame:CGRectMake(kMarginW, CGRectGetMaxY(self.productDateLabel.frame), leftLabelW, kLabelH)];
        [self.modelLabel setFrame:CGRectMake(CGRectGetMaxX(self.installDateLabel.frame)+kMarginW, CGRectGetMaxY(self.productDateLabel.frame), rightLabelW, kLabelH)];
        [self.lastMaintenceTimeLabel setFrame:CGRectMake(kMarginW, CGRectGetMaxY(self.modelLabel.frame), ownCodeWidth, kLabelH)];
        
        [headView addSubview:self.ownCodeLabel];
        [headView addSubview:self.manufacturersLabel];
        [headView addSubview:self.productDateLabel];
        [headView addSubview:self.userYearLabel];
        [headView addSubview:self.installDateLabel];
        [headView addSubview:self.modelLabel];
        [headView addSubview:self.lastMaintenceTimeLabel];

        CGFloat equipmentW = SCREEN_WIDTH - kMarginW * 4 - KEquipmentImageSize;
        [self.equipmentNameLabel setFrame:CGRectMake(kMarginW, CGRectGetMaxY(_lastMaintenceTimeLabel.frame)+ kGapH, equipmentW, KEquipmentImageSize * 2 / 3 - 5)];
        [headView addSubview:self.equipmentNameLabel];
        
        [self.equipmentImageView setFrame:CGRectMake(SCREEN_WIDTH - kMarginW - KEquipmentImageSize, self.equipmentNameLabel.y, KEquipmentImageSize, KEquipmentImageSize)];
        [headView addSubview:self.equipmentImageView];
        
        UIView* tableHeadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 5 * kLabelH + kGapH * 2 + KEquipmentImageSize + 20)];
        tableHeadView.backgroundColor = [UIColor customBackgroudColor];
        //        创建手势
        UITapGestureRecognizer* showMoreDetailVC = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showMoreDetailVC)];
        [headView addGestureRecognizer:showMoreDetailVC];
        [tableHeadView addSubview:headView];
        _headView = tableHeadView;
    }
    return _headView;
}

#pragma mark - Gesture Action
- (void)showMoreDetailVC
{
    YWEquipmentMoreDetailTableViewController* equipmentMoreDetailVC = [YWEquipmentMoreDetailTableViewController new];
    equipmentMoreDetailVC.equipmentDataSource = self.equipmentDataSource;
    equipmentMoreDetailVC.titleDataSource = self.titleDataSource;
    equipmentMoreDetailVC.equipmentTypeId = self.equipment.equipmentTypeId;
    equipmentMoreDetailVC.equipmentId = self.equipment.equipmentId;
    [self.navigationController pushViewController:equipmentMoreDetailVC animated:true];
}

- (UILabel*)equipmentNameLabel
{
    if (!_equipmentNameLabel) {
        UILabel* equipmentLabel = [[UILabel alloc] init];
        equipmentLabel.font = KTitleFont;
        equipmentLabel.text = self.equipment.equipmentName;
        equipmentLabel.textAlignment = NSTextAlignmentRight;
        _equipmentNameLabel = equipmentLabel;
    }
    return _equipmentNameLabel;
}
- (YWPhotoView*)equipmentImageView
{
    if (!_equipmentImageView) {
        NSArray* pictures = [[YWMissionManager shareManager] picturesWithEquipmentId:self.equipment.equipmentId pictureTroubleType:YWPictureTroubleTypeEquipment];
        if (pictures.count==0) {
            //这里是让又一个默认图片，不然是白的
            YWPicture *pic = [[YWPicture alloc] init];
            pictures = @[pic];
        }
        YWPhotoView* imageView = [[YWPhotoView alloc] init];
        imageView.photoWH = KEquipmentImageSize;
        imageView.canAddPhoto = NO;
        imageView.noPhotoGap = YES;
        imageView.photosArray = pictures;
        _equipmentImageView = imageView;
    }
    return _equipmentImageView;
}
//- (UILabel*)ownCodeL
//{
//    if (!_ownCodeL) {
//        UILabel* ownCodeL = [[UILabel alloc] init];
//        ownCodeL.font = kContentFont;
//        ownCodeL.text = @"用户自编码";
//        _ownCodeL = ownCodeL;
//    }
//    return _ownCodeL;
//}
- (UILabel*)ownCodeLabel
{
    if (!_ownCodeLabel) {
        UILabel* ownCodeLabel = [[UILabel alloc] init];
        ownCodeLabel.font = kContentFont;
//        ownCodeLabel.textAlignment = NSTextAlignmentRight;
        ownCodeLabel.text = [NSString stringWithFormat:@"用户自编码: %@",self.equipment.ownCode.length?self.equipment.ownCode:@"未填写"];
        _ownCodeLabel = ownCodeLabel;
    }
    return _ownCodeLabel;
}
//- (UILabel*)modelL
//{
//    if (!_modelL) {
//        UILabel* modelL = [[UILabel alloc] init];
//        modelL.font = kContentFont;
//        modelL.text = @"型号";
//        _modelL = modelL;
//    }
//    return _modelL;
//}
- (UILabel*)modelLabel
{
    if (!_modelLabel) {
        UILabel* modelLabel = [[UILabel alloc] init];
        modelLabel.font = kContentFont;
//        modelLabel.textAlignment = NSTextAlignmentRight;
        modelLabel.text = [NSString stringWithFormat:@"型号: %@",self.equipment.model.length?self.equipment.model:@"未填写"];
        _modelLabel = modelLabel;
    }
    return _modelLabel;
}
//- (UILabel*)factoryCodeL
//{
//    if (!_factoryCodeL) {
//        UILabel* factoryCodeL = [[UILabel alloc] init];
//        factoryCodeL.font = kContentFont;
//        factoryCodeL.text = @"厂商编码";
//        _factoryCodeL = factoryCodeL;
//    }
//    return _factoryCodeL;
//}
//- (UILabel*)factoryCodeLabel
//{
//    if (!_factoryCodeLabel) {
//        UILabel* factoryCodeLabel = [[UILabel alloc] init];
//        factoryCodeLabel.font = kContentFont;
//        factoryCodeLabel.textAlignment = NSTextAlignmentRight;
//        factoryCodeLabel.text = [NSString stringWithFormat:@"厂商编码: %@", self.equipment.factoryCode ?: @"无"];
//        _factoryCodeLabel = factoryCodeLabel;
//    }
//    return _factoryCodeLabel;
//}
//- (UILabel*)manufacturersL
//{
//    if (!_manufacturersL) {
//        UILabel* manufacturersL = [[UILabel alloc] init];
//        manufacturersL.font = kContentFont;
//        manufacturersL.text = @"制造商";
//        _manufacturersL = manufacturersL;
//    }
//    return _manufacturersL;
//}
- (UILabel*)manufacturersLabel
{
    if (!_manufacturersLabel) {
        UILabel* manufacturersLabel = [[UILabel alloc] init];
        manufacturersLabel.font = kContentFont;
//        manufacturersLabel.textAlignment = NSTextAlignmentRight;
        manufacturersLabel.text = [NSString stringWithFormat:@"厂商: %@",self.equipment.factoryName.length?self.equipment.factoryName:@"未填写"];
        _manufacturersLabel = manufacturersLabel;
    }
    return _manufacturersLabel;
}
//- (UILabel*)produceDateL
//{
//    if (!_produceDateL) {
//        UILabel* produceDateL = [[UILabel alloc] init];
//        produceDateL.font = kContentFont;
//        //        NSString *productDateStr = [YWCommonTool showChineseFormatterDate:self.equipment.produceDate/1000];
//        produceDateL.text = @"生产日期";
//        _produceDateL = produceDateL;
//    }
//    return _produceDateL;
//}
- (UILabel*)productDateLabel
{
    if (!_productDateLabel) {
        UILabel* productDateLabel = [[UILabel alloc] init];
        productDateLabel.font = kContentFont;
//        productDateLabel.textAlignment = NSTextAlignmentRight;
        NSString* productDateStr = self.equipment.produceDate>0?[YWCommonTool showDate:self.equipment.produceDate / 1000]:@"未填写";
        productDateLabel.text = [NSString stringWithFormat:@"生产日期: %@",productDateStr];
        _productDateLabel = productDateLabel;
    }
    return _productDateLabel;
}

//-(UILabel *)buyDateL{
//    if (!_buyDateL) {
//        UILabel *buyDateLabel = [[UILabel alloc]init];
//        buyDateLabel.font = kContentFont;
//        //        NSString *productDateStr = [YWCommonTool showChineseFormatterDate:self.equipment.produceDate/1000];
//        buyDateLabel.text = @"采购日期";
//        _buyDateL = buyDateLabel;
//    }
//    return _buyDateL;
//}
//-(UILabel *)buyDateLabel{
//    if (!_buyDateLabel) {
//        UILabel *buyDateLabel = [[UILabel alloc]init];
//        buyDateLabel.font = kContentFont;
//        buyDateLabel.textAlignment = NSTextAlignmentRight;
//        NSString *buyDateStr = [YWCommonTool showChineseFormatterDate:self.equipment.buyDate/1000];
//        buyDateLabel.text = buyDateStr?:@"无";//[NSString stringWithFormat:@"生产日期: %@",productDateStr?:@"无"];
//        _buyDateLabel = buyDateLabel;
//    }
//    return _buyDateLabel;
//}
//-(UILabel *)installDateL{
//    if (!_installDateL) {
//        UILabel* installDateL = [[UILabel alloc] init];
//        installDateL.font = kContentFont;
//        //        NSString *installDateStr = [YWCommonTool showChineseFormatterDate:self.equipment.installDate/1000];
//        installDateL.text = @"安装日期"; //[NSString stringWithFormat:@"安装日期: %@",installDateStr?:@"无"];
//        _installDateL = installDateL;
//    }
//    return _installDateL;
//}
- (UILabel*)installDateLabel
{
    if (!_installDateLabel) {
        UILabel* installDateLabel = [[UILabel alloc] init];
        installDateLabel.font = kContentFont;
//        installDateLabel.textAlignment = NSTextAlignmentRight;
        NSString* installDateStr = self.equipment.installDate>0?[YWCommonTool showDate:self.equipment.installDate / 1000]:@"未填写";
        installDateLabel.text = [NSString stringWithFormat:@"安装日期: %@",installDateStr];
        _installDateLabel = installDateLabel;
    }
    return _installDateLabel;
}
//- (UILabel*)lastMaintenceManL
//{
//    if (!_lastMaintenceManL) {
//        UILabel* lastMaintenceManL = [[UILabel alloc] init];
//        lastMaintenceManL.font = kContentFont;
//        //        YWLastMaintenanceTime* lastMaintenanceTime = [[YWEquipmentManager shareManager] lastMaintenanceTimeWithEquipmentId:self.equipment.equipmentId];
//        //        NSString *lastHandler = lastMaintenanceTime.executorName.length>0?lastMaintenanceTime.executorName:@"无";
//        lastMaintenceManL.text = @"上次检测人"; //[NSString stringWithFormat:@"上次检测人: %@",lastHandler];
//        _lastMaintenceManL = lastMaintenceManL;
//    }
//    return _lastMaintenceManL;
//}
//- (UILabel*)lastMaintenceManLabel
//{
//    if (!_lastMaintenceManLabel) {
//        UILabel* lastMaintenceManLabel = [[UILabel alloc] init];
//        lastMaintenceManLabel.font = kContentFont;
//        lastMaintenceManLabel.textAlignment = NSTextAlignmentRight;
//        YWLastMaintenanceTime* lastMaintenanceTime = [[YWEquipmentManager shareManager] lastMaintenanceTimeWithEquipmentId:self.equipment.equipmentId];
//        NSString* lastHandler = lastMaintenanceTime.executorName.length > 0 ? lastMaintenanceTime.executorName : @"无";
//        lastMaintenceManLabel.text = lastHandler; //[NSString stringWithFormat:@"上次检测人: %@",lastHandler];
//        _lastMaintenceManLabel = lastMaintenceManLabel;
//    }
//    return _lastMaintenceManLabel;
//}
//- (UILabel*)lastMaintenceTimeL
//{
//    if (!_lastMaintenceTimeL) {
//        UILabel* lastMaintenceTimeL = [[UILabel alloc] init];
//        lastMaintenceTimeL.font = kContentFont;
//        //        YWLastMaintenanceTime* lastMaintenanceTime = [[YWEquipmentManager shareManager] lastMaintenanceTimeWithEquipmentId:self.equipment.equipmentId];
//        //        NSString* maintenanceTime = [YWCommonTool showChineseFormatterDate:lastMaintenanceTime.maintenanceDate / 1000];
//        lastMaintenceTimeL.text = @"上次检测时间"; //[NSString stringWithFormat:@"上次检测时间: %@",maintenanceTime];
//        _lastMaintenceTimeL = lastMaintenceTimeL;
//    }
//    return _lastMaintenceTimeL;
//}
- (UILabel*)lastMaintenceTimeLabel
{
    if (!_lastMaintenceTimeLabel) {
        UILabel* lastMaintenceTimeLabel = [[UILabel alloc] init];
        lastMaintenceTimeLabel.font = kContentFont;
//        YWLastMaintenanceTime* lastMaintenanceTime = [[YWEquipmentManager shareManager] lastMaintenanceTimeWithEquipmentId:self.equipment.equipmentId];
        NSString* maintenanceTime = @"无";//lastMaintenanceTime.maintenanceDate>0?[YWCommonTool showChineseFormatterDate:lastMaintenanceTime.maintenanceDate / 1000]:@"无";
        lastMaintenceTimeLabel.text = [NSString stringWithFormat:@"上次检测: %@",maintenanceTime];
        _lastMaintenceTimeLabel = lastMaintenceTimeLabel;
    }
    return _lastMaintenceTimeLabel;
}

//
//- (UILabel*)userYearL
//{
//    if (!_userYearL) {
//        UILabel* userYearL = [[UILabel alloc] init];
//        userYearL.font = kContentFont;
//        userYearL.text = @"使用年限"; //[NSString stringWithFormat:@"使用年限: %ld年",(long)self.equipment.durableYears];
//        _userYearL = userYearL;
//    }
//    return _userYearL;
//}
- (UILabel*)userYearLabel
{
    if (!_userYearLabel) {
        UILabel* userYearLabel = [[UILabel alloc] init];
        userYearLabel.font = kContentFont;
//        userYearLabel.textAlignment = NSTextAlignmentRight;
        NSString *userYear = self.equipment.durableYears>0?[NSString stringWithFormat:@"%ld年",(long)self.equipment.durableYears]:@"未填写";
        userYearLabel.text = [NSString stringWithFormat:@"使用年限: %@",userYear];
        _userYearLabel = userYearLabel;
    }
    return _userYearLabel;
}

@end
